/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package marsaMaroc.controllers;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import marsaMaroc.dao.ClientDAO;
import marsaMaroc.dao.FactureDAO;
import marsaMaroc.dao.ReclamationDAO;
import marsaMaroc.dao.SalarieDAO;
import marsaMaroc.model.Client;
import marsaMaroc.model.Compte;
import marsaMaroc.model.Facture;
import marsaMaroc.model.Reclamation;
import marsaMaroc.model.Salarie;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Administrateur
 */
@Controller
public class HomeController {

    @RequestMapping(value = "/Acceuil.htm", method = RequestMethod.GET)
    protected ModelAndView add(HttpServletRequest request) throws Exception {
 
      
        return new ModelAndView("index");
    }

    @RequestMapping(value = "/dashboard.htm", method = RequestMethod.GET)
    protected ModelAndView dash(HttpServletRequest request) throws Exception {
        if (request.getSession().getAttribute("compte") == null) {
            return new ModelAndView("index");
        }

        Compte cmp = (Compte) request.getSession().getAttribute("compte");
        Client c = new ClientDAO().getByAccount(cmp.getId());
     
        List<Facture> listFactures =  new ClientDAO().getAllFactures(c);
        List<Reclamation> listreclamation =  new ClientDAO().getAllReclamations(c);
        request.getSession().setAttribute("listFactures",listFactures );
        request.getSession().setAttribute("listreclamation",listFactures );
        request.getSession().setAttribute("listFacturesSize",listFactures.size() );
        request.getSession().setAttribute("listreclamationSize",listFactures.size() );
        
        return new ModelAndView("client_side/dash").addObject("reclamationCount", listreclamation.size()).addObject("facturesCount", listFactures.size());
    }

}
